package com.air.ota.net;

import java.util.Arrays;

import com.air.ota.util.HexStringUtil;
import com.air.ota.vo.SZTBaseResTransVO;
import com.air.ota.vo.SZTBaseResponseVO;

public class ResponseHandler {
	
	private byte[] response = null;
	
	public synchronized boolean handleResponse(byte[] rsp){
		this.response = rsp;
		this.notify();
		return true;
	}
	
	public synchronized void wait4Response(){
		while (this.response==null){
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			//System.out.println(new String(this.response));
			System.out.println("1response="+HexStringUtil.bytesToHexString(this.response));
			
			SZTBaseResponseVO responseVO = new SZTBaseResponseVO();
			responseVO.parse(this.response);
			SZTBaseResTransVO baseResTransVO = new SZTBaseResTransVO();
			baseResTransVO.parse(HexStringUtil.hexStringToBytes(responseVO.getData()));
			System.out.println("body="+responseVO.getData());
			System.out.println("transData.transResult="+HexStringUtil.byteToHexString(baseResTransVO.getTransResult()));
			System.out.println("transData.transResponseData="+HexStringUtil.bytesToHexString(baseResTransVO.getTransResponseData()));
			System.out.println("transData.mac="+HexStringUtil.bytesToHexString(baseResTransVO.getMac()));
		}
	}
	
}
